package com.example.springboot_demo.controller;

import com.example.springboot_demo.entity.ClazzRoom;
import com.example.springboot_demo.entity.User;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * apipost 文档地址：https://doc.apipost.net/docs/detail/320a3179e064000?target_id=20a5f7bffff010
*/
@Controller
@RequestMapping("/form")
public class FormController {
    private static final Logger log = LoggerFactory.getLogger(FormController.class);


    /**
     * 接收字符串传参！
     * 两个参数
     *
     * @param name
     */
    @RequestMapping("/StringValue")
    @ResponseBody
    public String receiveParameters(@RequestParam(value = "name1",required = false) String name, String pwd) {

        return name + ":" + pwd;
    }


    /**
     * 传入一个数组，后端自动封装成List集合
     * @param ids
     */
    @RequestMapping("/list")
    @ResponseBody
    public Map receiveParameters(@RequestParam List<Integer> ids){
        Map<Object, Object> hashMap = new HashMap<>();
        hashMap.put("ids",ids);
        hashMap.put("code",200);
        return hashMap;
    }

    /**
     * 支持query 和 表单传参
    */
    @RequestMapping("/obj")
    @ResponseBody
    public Map receiveParameters(User user){
        Map<Object, Object> hashMap = new HashMap<>();
        hashMap.put("data",user);
        hashMap.put("code",200);
        return hashMap;
    }

    /**
     * 支持json传参
     */
    @RequestMapping("/objJson")
    @ResponseBody
    public Map receiveParametersJson(@RequestBody User user){
        Map<Object, Object> hashMap = new HashMap<>();
        hashMap.put("data",user);
        hashMap.put("code",200);
        return hashMap;
    }

    /**
     * 嵌套对象 使用json传输
     * @param clazzRoom
     */
    @PostMapping("/ClazzUserValue2Json")
    @ResponseBody
    public Map<Object, Object> clazzUserValue2Json(@RequestBody ClazzRoom clazzRoom){
        Map<Object, Object> hashMap = new HashMap<>();
        hashMap.put("data",clazzRoom);
        hashMap.put("code",200);
        return hashMap;
    }





}
